#include <QtGui>

#include "gamemenu_frame.h"
#include "invader_label.h"
#include "invader_menu.h"

GameMenu::GameMenu (QWidget *parent)
  : QFrame (parent)
{
  QVBoxLayout *layout = new QVBoxLayout;

  layout->addWidget (new InvaderLabel ("space invaders", this),
                     0, Qt::AlignHCenter);

  QStringList items;
  items << "resume" << "reset game" << "reset highscore" << "exit";
  _menu = new InvaderMenu (items, this);
  _menu->setFocusPolicy (Qt::ClickFocus);
  layout->addWidget (_menu, 0, Qt::AlignHCenter);
  connect (_menu, SIGNAL (itemSelected (unsigned int)), 
           this, SLOT (menuItemSelected (unsigned int)));

  setLayout (layout);
}

void GameMenu::focusInEvent (QFocusEvent *event)
{
  _menu->setSelected (0);
  _menu->setFocus ();
}

void GameMenu::menuItemSelected (unsigned int item)
{
  switch (item) {
    case 0: emit resume (); break;
    case 1: emit restart (); break;
    case 2: emit clearHighscore (); break;
    case 3: emit quit (); break;
    default: break;
  }
}
